package thirdpart.codec;

import com.alipay.remoting.serialization.SerializerManager;

import java.io.Serializable;
import java.util.Calendar;

/**
 * @Author: Tzu
 * @Date: 2020/11/11 21:00
 * @Version: 1.0
 * @Description:
 */
public class BodyCodec implements IBodyCodec {
    @Override
    public <T> byte[] serialize(T obj) throws Exception {
        //1、jdk序列化；2、json；3、自定义算法（Hessian2）
        return SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(obj);
    }

    @Override
    public <T> T deserialize(byte[] bytes, Class<T> clazz) throws Exception {
        return SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize(bytes,clazz.getName());
    }



//    public static void main(String[] args) throws Exception {
//        A a = new A();
//        a.s = "test";
//
//        byte[] serialize = new BodyCodecImpl().serialize(a);
//        A deserialize = new BodyCodecImpl().deserialize(serialize, A.class);
//        System.out.println(deserialize.s);
//    }
//
//    static class A implements Serializable {
//        public String s;
//    }

}
